﻿<div ms-controller="DSETINDEX">
    <!-- 添加按钮 -->
    <div class="btn-add">
        <button type="button" class="btn btn-info btn-lg" ms-click="Add()"><i class="iconfont icon-jiahao ft12 mr5"></i>新建数据集</button>
    </div>
    <!-- 按条件选择 -->
    <div class="tab-filter-type">
        <div class="oh">
            <h5 class="pull-left tr">全部类型：</h5>
            <ul class="tab-type ft14">
                <li><span class="active">我的数据集</span></li>
            </ul>
        </div>
    </div>
    <!-- 表格 -->    
    <div class="default-tab ft14 pt20 hover-btn">
        <table class="table table-striped table-responsive table-hover">
            <thead>
                <tr>
                    <th class="tc width-70">
                        序号
                    </th>
                    <th>名称</th>
                    <th>所属数据源</th>
                    <th>创建人</th>
                    <th>创建时间</th>
                    <th width="10%">操作</th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-item="DSetList">
                    <td class="tc">
                        {{$index+1}}
                    </td>
                    <td class="lk">{{item.Name}}</td>
                    <td>{{item.SJY}}</td>

                    <td>{{item.CRUser}}</td>
                    <td>{{item.CRDate|date("yyyy-MM-dd HH:mm")}}</td>
                    <td>
                        <span class="btn-click">
                            
                            <a class="cz-btn ft18 bj-color tip" data-toggle="tooltip" title="编辑"  ms-click="Edit(item)">
                                <i class="iconfont icon-shezhi"></i>
                            </a>
                            <a class="cz-btn ft18 bj-color tip" data-toggle="tooltip" title="设计" target="_blank" ms-attr-href="/ViewV5/AppPage/DATABI/DSETEDIT.html?ID={{item.ID}}">
                                <i class="iconfont icon-bianji"></i>
                            </a>
                            <a class="cz-btn ft18 sc-color tip" data-toggle="tooltip" title="删除" ms-click="Del(item)">
                                <i class="iconfont icon-shanchu"></i>
                            </a>
                        </span>
                    </td>
                </tr>
            </tbody>

        </table>



        <div class="modal fade" id="DModal" role="dialog">
            <div class="modal-dialog" role="document" style="width: 700px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">添加数据集</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-horizontal">

                            <div class="form-group">
                                <label for="branchName" class="col-xs-3 control-label text-right">数据集名称</label>
                                <div class="col-xs-7">
                                    <input type="text" class="form-control" id="DSName" placeholder="数据集名称" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="branchName" class="col-xs-3 control-label text-right">数据源</label>
                                <div class="col-xs-7">
                                    <select id="DTS" class="form-control">
                                        <option value="0">本地数据源</option>
                                        <option ms-repeat-item="DSourData" ms-attr-value="item.ID">{{item.Name}}</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="branchName" class="col-xs-3 control-label text-right">数据集类型</label>
                                <div class="col-xs-7">
                                    <select id="DType" class="form-control">
                                        <option value="SQL">自定义SQL模型</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-info" ms-click="ConfirmData()">确认</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>

    var tempindex = avalon.define({
        $id: "DSETINDEX",
        DSetList: [],//
        DSourData:[],
        DSData: {},
        isedit:0,
        InitWigetData: function () {
            $.getJSON('/api/Bll/ExeAction?Action=DATABI_GETBIDBSETLIST', {}, function (resultData) {
                if (resultData.Result.length > 0) {
                    tempindex.DSetList = resultData.Result;
                    tempindex.DSourData = resultData.Result2;

                }
            })
        },
    
        Del: function (item) {
            top.ComFunJS.winconfirm("确认要删除吗", function () {
                $.getJSON('/api/Bll/ExeAction?Action=DATABI_DELBIDBSET', { "P1": item.ID }, function (result) {
                    if (result.ErrorMsg == "") {
                        top.ComFunJS.winsuccess("删除成功");
                        tempindex.DSetList.remove(item);
                    }
                })
            }, function () { })
        },
        Add: function () {
            tempindex.isedit = 0;
            $('#DModal').modal('show');
        },
        Edit: function (item) {
            tempindex.isedit = 1;
            tempindex.DSData = item.$model;
            $("#DTS").val(item.SID)
            $("#DSName").val(item.SName)
            $('#DModal').modal('show');
        },
        ConfirmData: function () {
            if (tempindex.isedit == 0) {
                tempindex.DSData = { Name: $("#DSName").val(), SName: $("#DSName").val(), Type: $("#DType").val(), ID: "0", SID: $("#DTS").val() };
            } else {
                tempindex.DSData.SID = $("#DTS").val();
                tempindex.DSData.SName = $("#DSName").val();
                tempindex.DSData.Name = $("#DSName").val();

            }
            $.getJSON('/api/Bll/ExeAction?Action=DATABI_ADDBIDBSET', { P1: JSON.stringify(tempindex.DSData.$model) }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    top.ComFunJS.winsuccess("操作成功");
                    tempindex.InitWigetData();
                    $('#DModal').modal('hide');

                }
            })
        }
     
    })
    //# sourceURL=DSETINDEX.js;
</script>